package com.sunleader.netboot.module.machine.dto;

import com.sunleader.netboot.module.machine.model.Machine;
import lombok.Data;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class Lease {
    public DHCP dhcp;

    @Data
    static class DHCP{
        private Map<String, LeaseMachine> binding;

        public DHCP(List<Machine> machines) {
            binding = machines.stream().collect(Collectors.toMap(Machine::getMac,machine -> new LeaseMachine(machine)));
        }
    }


    @Data
    static class LeaseMachine{
        private String mac;
        private String name;
        private String ipaddr;
        private String router;
        private String subnet;
        private String rom;
        private Boolean needReload;
        private String status;

        public LeaseMachine(Machine machine) {
            this.mac = machine.getMac();
            this.ipaddr = machine.getIp();
            this.router = machine.getRouter();
            this.subnet = machine.getSubnet();
            this.rom = machine.getRom();
            this.needReload = machine.getNeedReload();
            this.status = machine.getStatus();
        }
    }
    public Lease(List<Machine> machines){
        dhcp = new DHCP(machines);
    }
}
